The visibility
property in CSS is used to control whether an element is visible or hidden, without affecting the layout of the document. Unlike the display: none
property, which removes the element from the document flow, visibility: hidden
keeps the element in the flow, but makes it invisible. Here are the common values for the visibility
property:
You can set the visibility
property with the following values:
visibility: visible
The element is visible (default value):
visibility: hidden
The element is hidden, but it still takes up space in the layout:
visibility: collapse
This value is primarily used with table rows and columns. It hides the element and also collapses the space it occupies (similar to display: none
for table elements):
Here is an example that demonstrates the use of the visibility
property:
Imagine you have a notification box that you want to hide without affecting the layout:
Using the visibility
property, you can control the visibility of elements in a way that suits your design requirements. Let me know if you need more details or examples!